package com.br.cashflowdao.hibernate.dao.entities;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author Marcel Sena <marcel.sena at marcel.sena@gmail.com>
 * @version 1.0
 * @since 05/01/2009
 */
@Entity
@Table(name="PAYEE"
    ,catalog="cashflow"
)
public class Payee  implements java.io.Serializable, IEntity {

    private Long id;
    private String name;
    private Date createDate;
    private Date updateDate;
    private Set<CreditTransaction> creditTransactions = new HashSet<CreditTransaction>(0);

    public Payee() {}

	public Payee(Date createDate, String name, Date updateDate) {
        this.createDate = createDate;
        this.name = name;
        this.updateDate = updateDate;
    }

    @Id @GeneratedValue(strategy=IDENTITY)
    @Column(name="ID", unique=true, nullable=false)
    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name="NAME", nullable=false, length=100 )
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Temporal(TemporalType.DATE)
    @Column(name="CREATE_DATE", nullable=false, length=10)
    public Date getCreateDate() {
        return this.createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @Temporal(TemporalType.DATE)
    @Column(name="UPDATE_DATE", nullable=false, length=10)
    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="payee")
    public Set<CreditTransaction> getCreditTransaction() {
        return creditTransactions;
    }

    public void setCreditTransaction(Set<CreditTransaction> creditTransaction) {
        creditTransactions = creditTransaction;
    }

    public void addCreditTransaction(CreditTransaction creditTransaction) {
        creditTransactions.add(creditTransaction);
    }
}